<?php
include("Config.php");
include("Mysql_class.php");
if(isset($_GET['act'])){
	
	switch($_GET['act']){
		case "login":
		loginer();
		break;
		case "logout":
		logout();
		break;			
		default:echo "ERROR!!!!";
		break;
	}
}
else{
	echo "ERROR!!!";exit;
}

//管理登录
function loginer(){
	global $conf;
	$uname = isset($_POST['t0'])?trim($_POST['t0']):"";
	$upass = isset($_POST['t1'])?trim($_POST['t1']):"";
	if(empty($uname)){ $str = array("0","请输入登录帐号"); echo json_encode($str);exit;}
	if(empty($upass)){ $str = array("0","请输入登录密码"); echo json_encode($str);exit;}
	$db =  new db($conf);
	$field = array("*");
	$where = array("auname"=>"'".$uname."'","apwd"=>"'".MD5($upass)."'","astate"=>1);
	$result = $db->field($field)
			->where($where)
			->select("sc_admin");
	if($result){
		if($result[0]['auname']!=$uname || $result[0]['apwd']!=MD5($upass) || $result[0]['astate']!=1){
			$str = array("0","帐号或密码错误");
			echo json_encode($str);exit;
		}
		$_SESSION['a']['atname'] = $result[0]['atname'];
		$_SESSION['a']['auserid'] = $result[0]['Id'];
		$_SESSION['a']['auname'] = $result[0]['auname'];
		$_SESSION['a']['alevel'] = $result[0]['alevel'];
		$_SESSION['a']['atime'] = time();
		$str = array("1","登录成功，请稍等");
		echo json_encode($str);
	}
	else{
		$str = array("0","帐号或密码错误");
		echo json_encode($str);
	}
}

//退出登录
function logout(){
	session_destroy();
	$str = array(1,"退出登录成功");
	echo json_encode($str);
}
?>